# SOFT_HOME = /storage/hpcauser/zongyi/HUAWEI/software
# HYPRE_F64_VER = recmat
# HYPRE_F64_HOME = $(SOFT_HOME)/hypre-hpcx-2.7.0/recmat

# Modify to the installed address of hypre
HYPRE_F64_HOME = /online1/ycsc_xuew/xuew/zongyi/software/hypre/recmat
# HYPRE_F64_HOME = /storage/hpcauser/zongyi/HUAWEI/software/hypre-hpcx-2.7.0/recmat

HYPRE_F64_LIB  = $(HYPRE_F64_HOME)/lib
HYPRE_F64_INCLUDE = $(HYPRE_F64_HOME)/include
L_F64_HYPRE = -L$(HYPRE_F64_LIB) -lHYPRE

# Modify to the installed address of direct sparse solver (here, MKL for x86 and tydss for aarch64)
MKL_HOME = $(MKLROOT)
MKL_LIB  = $(MKL_HOME)/lib/intel64
MKL_INC = -I$(MKL_HOME)/include
LAPACK = -L$(MKL_LIB) -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core
SCALAP = -L$(MKL_LIB) -lmkl_scalapack_lp64 -lmkl_blacs_intelmpi_lp64 -Wl,-rpath=$(MKL_LIB)
LMKL = $(LAPACK) $(SCALAP)

# TYDSS_HOME = /storage/hpcauser/zongyi/HUAWEI/software/tydss_v1.0.0
# TYDSS_INC = -I$(TYDSS_HOME)/include
# LTYDSS = -L$(TYDSS_HOME)/lib -ltydss -Wl,-rpath=$(TYDSS_HOME)/lib

# Modify to the installed address of jsoncpp
# JSON_HOME = /storage/workshop/jsoncpp 
JSON_HOME = /home/export/base/ycsc_xuew/xuew/online1/yupn/jsoncpp
JSON_INC = -I$(JSON_HOME)/include
JSON_LIB = -L$(JSON_HOME)/build/debug/lib -ljsoncpp -Wl,-rpath=$(JSON_HOME)/build/debug/lib

EXT_LD = $(LTYDSS) $(LMKL) $(JSON_LIB)

# Modify to the installed address of Semi-StructMG (could be downloaded from the repo)
SSTRUCTMG_HOME = /home/export/base/ycsc_xuew/xuew/online1/zongyi/SStructMG-public
SSTRUCTMG_INC = $(SSTRUCTMG_HOME)/include
SSTRUCTMG_LIB = $(SSTRUCTMG_HOME)/lib
L_SSTRUCTMG = -L$(SSTRUCTMG_LIB) -lSstructmg -Wl,-rpath=$(SSTRUCTMG_LIB) $(EXT_LD)

DEBUG = #-D_zyDEBUG

# IntelMPI + icpc
CXX= mpiicpc

# OpenMPI + icpc (needs to specify OMPI_CXX) on x86, or OpenMPI + g++ on aarch64
# CXX=mpicxx
# CXX=/apps/compilers/openmpi/4.1.2/bin/mpicxx

# IntelMPI + OneAPI DPC++/C++
#CXX=mpiicc -cc=icpx

OMP = -fopenmp
CFLAGS = -O3 -std=c++17 -g -DTEST_CNT=10 $(OMP) $(DEBUG)

CL = $(CXX)
LFLAGS = -lm -fopenmp -ldl

all:	base_case3.exe base_case4.exe base_kvlcc2.exe base_gfs.exe base_oil.exe base_ocean.exe \
		test_case3.exe test_case4.exe test_kvlcc2.exe test_gfs.exe test_oil.exe test_ocean.exe

base_%.exe: base_%.o wrapper_hypre.o
	$(CXX) $^ $(L_F64_HYPRE) $(LFLAGS) -o $@
wrapper_hypre.o: wrapper_hypre.cpp
	$(CXX) $(CFLAGS) 		   -I$(HYPRE_F64_INCLUDE) -c $^ -o $@
base_%.o: base_%.cpp
	$(CXX) $(CFLAGS) -D_addety -I$(HYPRE_F64_INCLUDE) -c $^ -o $@

test_%.exe: test_%.o wrapper_sstructmg.o
	$(CXX) $^ $(L_SSTRUCTMG) $(LFLAGS) -o $@
wrapper_sstructmg.o: wrapper_sstructmg.cpp
	$(CXX) $(CFLAGS) -I$(SSTRUCTMG_INC) -c $^ -o $@
test_%.o: test_%.cpp
	$(CXX) $(CFLAGS) -I$(SSTRUCTMG_INC) -c $^ -o $@

default: all
.PHONY: all clean

clean:
	rm *.o *.exe

